package com.xyebank.ledger.service.nx.dataprovider.apply;


import com.xyebank.ledger.service.common.DataProvider;
import com.xyebank.ledger.vo.deal.LNxCashApplicationInfVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class NxApplyDataProvider implements DataProvider<LNxCashApplicationInfVo> {

    @Autowired
    private SNxCashApplyMapper mNxCashApplyMapper;

    @Override
    public List<LNxCashApplicationInfVo> get(Integer fromIdx, Integer tarNum) {
        List<SNxCashApply> result = mNxCashApplyMapper.selectByPaging(fromIdx, tarNum);
        List<LNxCashApplicationInfVo> list = convert2Vo(result);
        return list;
    }


    @Override
    public List<LNxCashApplicationInfVo> get(Date dateStart, Date dateEnd, Integer fromIdx, Integer tarNum) {
        List<SNxCashApply> result = mNxCashApplyMapper.selectByPeriod(dateStart, dateEnd, fromIdx, tarNum);
        List<LNxCashApplicationInfVo> list = convert2Vo(result);
        return list;
    }


    @Override
    public Integer count(Date timeStart, Date timeEnd) {
        Integer count = mNxCashApplyMapper.selectPeriodCount(timeStart, timeEnd);
        return count;
    }


    private List<LNxCashApplicationInfVo> convert2Vo(List<SNxCashApply> result) {
        List<LNxCashApplicationInfVo> list = new ArrayList<LNxCashApplicationInfVo>();
        for (int i = 0; i < result.size(); i++) {
            LNxCashApplicationInfVo vo = new LNxCashApplicationInfVo();
            BeanUtils.copyProperties(result.get(i), vo);
            list.add(vo);
        }
        return list;
    }

}
